#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int n, m;
int p[N];
int st[N];
vector<int>g[N];
//int a[N], b[N];
int s[N];
int find(int x)
{
	if (x != p[x])p[x] = find(p[x]);
	return p[x];
}

bool f1;
void dfs(int u, int fa)
{
	st[u] = 1;
	for (auto x : g[u]) {
		if (x != fa) {
			if (s[x] > 2 || st[x]) {
				f1 = 1;
				return;
			}
			dfs(x, u);
		}
	}
	return;
}

int main()
{
	int t;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d", &n, &m);
		if (!m) {
			printf("No\n");
			continue;
		}
		for (int i = 1; i <= n; i++) {
			p[i] = i;
			s[i] = 0;
			g[i].clear();
			st[i] = 0;
		}
		bool f = 0;
		int cnt1 = 0;
		/*for (int i = 1; i <= m; i++) {
			scanf_s("%d%d", &a[i], &b[i]);
			int a1 = find(a[i]);
			int b1 = find(b[i]);
			if (a1 == b1)f = 1;
			p[a1] = b1;
			s[a[i]]++;
			s[b[i]]++;
			g[a[i]].push_back(b[i]);
			g[b[i]].push_back(a[i]);
		}*/
		for (int i = 1; i <= m; i++) {
			int a, b;
			scanf("%d%d", &a, &b);
			int a1 = find(a);
			int b1 = find(b);
			if (a1 == b1)f = 1;
			p[a1] = b1;
			s[a]++;
			s[b]++;
			g[a].push_back(b);
			g[b].push_back(a);
		}
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			if (s[i] > 2 && !st[i]) {
				//cout << "i==" << i << endl;
				f1 = 0;
				dfs(i, -1);
				if (!f1)cnt++;
			}
		}
		//cout << "---------------" << endl;
		//cout << "f==" << f << endl;
		//cout << "cnt==" << cnt << endl;
		//cout << "cnt1==" << cnt1 << endl;
		if (cnt >= 1)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}